{extend name="public:base"}
{block name='css'}
<link href="__PUBLIC__/css/plugins/iCheck/custom.css" rel="stylesheet">
{/block}
{block name="js"}
<script src="__PUBLIC__/js/content.min.js?v=1.0.0"></script>
<script src="__PUBLIC__/js/plugins/validate/jquery.validate.min.js"></script>
<script src="__PUBLIC__/js/plugins/validate/messages_zh.min.js"></script>
<script type="text/javascript">
	$.validator.setDefaults({
		highlight: function(e) {
			$(e).closest(".form-group").removeClass("has-success").addClass("has-error")
		},
		success: function(e) {
			e.closest(".form-group").removeClass("has-error").addClass("has-success")
		},
		errorElement: "span",
		errorPlacement: function(e, r) {
			e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
		},
		errorClass: "help-block m-b-none",
		validClass: "help-block m-b-none"
	});
	$().ready(function() {
		var e = "<i class='fa fa-times-circle'></i> ";
		$("#commentForm").validate({
			rules: {
				title: "required"
			},
			messages: {
				title: e + "请输入用户组名称"
			},
			submitHandler: function(form){
				if ($(form).hasClass('ed')) {
					return false;
				}

				$(form).addClass('ed');
				var obj = showMyLoading();
				$.post('', $(form).serialize(), function(data){
                    hideMyLoading(obj);
					layer.msg(data.info);
					if (data.status == 'y') {
						window.location.href = '{:url("index")}';
					} else {
						$(form).removeClass('ed');
					}
				}, 'json');
			},
			invalidHandler: function(form, validator) {  //不通过回调
				return false;
			}
		})
	});

	function check(obj){

		var checked=$(obj).is(':checked');
		var controller=$(obj).attr('controller');

		if(controller == '#'){ //下面全部选中或全部取消
			if(checked){ //全部选中

				var input=$(obj).parent().parent().next().find('input');
				input.each(function(){
					$(this).prop("checked",true);

				})

			}else{ //全部取消选中
				var input=$(obj).parent().parent().next().find('input');
				input.each(function(){
					$(this).prop("checked",false);

				})
			}

		}

		var length=$('.hierarchyOne ul').length;
		$('.hierarchyOne ul').each(function(i){
			var tue=false;
			var oneThis=$('.hierarchyOne ul').eq(length-i-1);
			oneThis.find('input').each(function(){
				if($(this).is(':checked')){
					tue=true;
					return false;
				}
			});
			if(tue){
				var input=oneThis.prev().find('input');
				if(!input.is(':checked')){
					input.prop('checked',!input.is(':checked'));
				}
			}else{
				var input=oneThis.prev().find('input');
				if(input.is(':checked')){
					input.prop('checked',!input.is(':checked'));
				}
			}
		})


	}
</script>
{/block}
{block name='body'}
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>添加用户组</h5>
                        <a href="javascript:history.go(-1);" class="btn btn-sm btn-primary pull-right m-t-n-xs">返回</a>
                    </div>
                    <div class="ibox-content">
                        <form method="post" class="form-horizontal" id="commentForm" action="" enctype="multipart/form-data" >
                            <div class="form-group">
                                <label class="col-sm-2 control-label">用户组名称</label>
                                <div class="col-sm-10">
                                    <input type="text" name="title" class="form-control">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">操作权限</label>
                                <div class="col-sm-10">
									{:nav($linkList)}
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary" type="submit">保存内容</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
{/block}
